import pygame

class APC(pygame.sprite.Sprite):
    def __init__(self,screen_size):
        pygame.sprite.Sprite.__init__(self)
        #self.image = pygame.image.load("1002/100201_01.png").convert_alpha()
        self.width, self.height = screen_size[0], screen_size[1]
        self.roadTop = self.height//2-100
        self.idleimgs = []
        self.idleimgs1 = []
        self.idleimgs1.extend([pygame.image.load("1002/1002_idle_01.png").convert_alpha(),\
                              pygame.image.load("1002/1002_idle_02.png").convert_alpha(),\
                              pygame.image.load("1002/1002_idle_03.png").convert_alpha(),\
                              pygame.image.load("1002/1002_idle_04.png").convert_alpha(),\
                              pygame.image.load("1002/1002_idle_05.png").convert_alpha(),\
                              pygame.image.load("1002/1002_idle_06.png").convert_alpha(),\
                              pygame.image.load("1002/1002_idle_07.png").convert_alpha(),\
                              pygame.image.load("1002/1002_idle_08.png").convert_alpha()])

        self.idleimgs2 = []

        for i in range(8):
            self.idleimgs2.append(pygame.transform.flip(self.idleimgs1[i],True,False))
        #初始状态
        self.idleimgs = self.idleimgs2
        '''
        self.idleimgs1.extend([pygame.image.load("1002/1001_walk_01.png").convert_alpha(),\
                              pygame.image.load("1002/1001_walk_02.png").convert_alpha(),\
                              pygame.image.load("1002/1001_walk_03.png").convert_alpha(),\
                              pygame.image.load("1002/1001_walk_04.png").convert_alpha(),\
                              pygame.image.load("1002/1001_walk_05.png").convert_alpha(),\
                              pygame.image.load("1002/1001_walk_06.png").convert_alpha(),\
                              pygame.image.load("1002/1001_walk_07.png").convert_alpha(),\
                              pygame.image.load("1002/1001_walk_08.png").convert_alpha()])
         '''
        self.rect = self.idleimgs[0].get_rect()
        self.rect.left, self.rect.top = self.width-self.rect.width,self.roadTop
        self.speed = 2
        self.active = True
        self.mask = pygame.mask.from_surface(self.idleimgs[0])
        self.blood = 3

    def moveUp(self):
        if self.rect.top > self.roadTop:
            self.rect.top -= self.speed
        else:
            self.rect.top = self.roadTop
    def moveDown(self):
        if self.rect.bottom < self.height:
            self.rect.bottom += self.speed
        else:
            self.rect.bottom = self.height
    def moveLeft(self):
        self.idleimgs = self.idleimgs2
        if self.rect.left > 0:
            self.rect.left -= self.speed
        else:
            self.rect.left = 0
    def moveRight(self):
        self.idleimgs = self.idleimgs1
        if self.rect.right < self.width:
            self.rect.right += self.speed
        else:
            self.rect.right = self.width
    def clear(self):
        self.rect.left = 2*self.width
        self.rect.top = -self.height
